#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using std::cout;
using std::endl;
using std::vector;
using std::for_each;
using std::copy;
using std::ostream_iterator;

void func(int &value)
{
    ++value;
    cout << value << "  ";
}

void test()
{
    vector<int> number = {1, 4, 7, 9, 5, 3, 7};
    copy(number.begin(), number.end(), 
         ostream_iterator<int>(cout, "  "));
    cout << endl;

    /* [](int &value){++value;cout << value << "  ";}; */

    int a = 10;
    /* for_each(number.begin(), number.end(), func); */
    //lambda表达式--->匿名函数
    //[]称为捕获列表
    //要想修改a的值，可以引用传递或者添加mutable关键字
    for_each(number.begin(), number.end(), [&a](int &value)mutable->void{
             ++a;
             cout << "a = " << a << endl;
             ++value;
             cout << value << "  ";

             });
    cout << endl;

    copy(number.begin(), number.end(), 
         ostream_iterator<int>(cout, "  "));
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

